package com.ie.controller;

import com.ie.common.http.Result;
import com.ie.common.http.ResultCodeEnum;
import com.ie.entity.Community;
import com.ie.service.CommunityService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/system/community")
public class CommunityController
{
    @Autowired
    private CommunityService communityService;

    //获取所有
    @GetMapping("/all")
    public List<Community> getAllCommunity()
    {
        return communityService.getAllCommunity();
    }

    //删除
    @DeleteMapping("/delete")
    public boolean deleteCommunity(@RequestParam("id") String id)
    {
        return communityService.deleteCommunity(id);
    }

    //点赞
    @PutMapping("/like")
    public boolean likeCommunity(@RequestParam("id") String userid, @RequestParam("likeid") String likeid)
    {

        if (communityService.likeCommunity(userid, likeid)) {
            return true;
        }
         return false;
    }

    //查询用户是否点赞
    @GetMapping("/unlike")
    public boolean unlikeCommunity(@RequestParam("id") String userid, @RequestParam("likeid") String likeid)
    {
        return communityService.unlikeCommunity(userid, likeid);
    }


    /**
     * 发表
     */
    @PostMapping("/add")
    public Result addCommunity(@RequestBody Community community) {
        communityService.addCommunity(community);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

}
